/*
 * branch_traces.c
 *
 *  Created on: Feb 13, 2014
 *      Author: Raviraj
 */


#include "includes.h"

extern FILE *B_TRACE;

void write_branch_traces(char* branch_type, unsigned short instruction_PC, unsigned short target_PC, int branch_taken)
{
	if(strcmp(branch_type,"JSR")==0 || strcmp(branch_type,"JMP")==0 || strcmp(branch_type,"RTS")==0)
	{
		if(branch_taken)
			fprintf(B_TRACE," %s\t\tJUMP or SUBROUTINE\t%.6o\t\t%.6o\t\tTaken\n", branch_type, instruction_PC, target_PC);
		else
			fprintf(B_TRACE," %s\t\tJUMP or SUBROUTINE\t%.6o\t\t%.6o\t\tNot taken\n", branch_type, instruction_PC, target_PC);
	}
	//else if(branch_type == "BR")
	else if(strcmp(branch_type,"BR") == 0)
	{
		if(branch_taken)
			fprintf(B_TRACE," %s\t\t\tUnconditional\t\t%.6o\t\t%.6o\t\tTaken\n", branch_type, instruction_PC, target_PC);
		else
			fprintf(B_TRACE," %s\t\t\tUnconditional\t\t%.6o\t\t%.6o\t\tNot taken\n", branch_type, instruction_PC, target_PC);
	}
	else
	{
		if(branch_taken)
			fprintf(B_TRACE," %s\t\tConditional\t\t\t%.6o\t\t%.6o\t\tTaken\n", branch_type, instruction_PC, target_PC);
		else
			fprintf(B_TRACE," %s\t\tConditional\t\t\t%.6o\t\t%.6o\t\tNot taken\n", branch_type, instruction_PC, target_PC);
	}
}
